import random

class Unit:
	def __init__(self, utype, team, motionType, defense, strength, speed, luck, skill, movement,aiType, health=10, ableToCapture=True, state='unmoved', inventory = None):
		self.movement=movement
		self.team=team
		self.motionType=motionType
		self.utype=utype
		self.strength=strength
		self.state=state
		self.health=health
		self.ableToCapture=ableToCapture
		self.defense=defense
		self.skill=skill
		self.speed=speed
		self.luck=luck
		self.inventory = inventory
		self.secondaryWeapon=None
		self.destination=(0,0)
		#AI type: 'A' is attacking, 'D' is Defending, 'M' is moving
		self.aitype=aiType[0]#type is always the first character
		#target for move AI. The target cell as a tuple (row,col)
		aiSplit = aiType.split(",")
		if len(aiSplit) == 3:
			self.destination=(int(aiSplit[1]),int(aiSplit[2]))
	
	def getSkill(self):
		return self.skill
	def setaitype(self,input):
		if input in ['A','D','M']:
			self.aitype = input
	def setdestination(self, x,y):
		self.destination = (x,y)
	def getaitype(self):
		return self.aitype
	def getdestination(self):
		return self.destination
	def getMovement(self):
		return(self.movement)
	def getType(self):
		return(self.utype)
	def getTeam(self):
		return(self.team)
	def getHealth(self):
		return(self.health)
	def setHealth(self,health):
		self.health=health
	def getState(self):
		return(self.state)
	def setState(self,state):
		self.state=state
		return
	def getMotionType(self):
		return(self.motionType)
	def setAbleToCapture(self,ableToCapture):
		self.ableToCapture=ableToCapture
	def getAbleToCapture(self):
		return(self.ableToCapture)
	def getPrimaryWeapon(self):
		return(self.inventory[0])
		#return(self.primaryWeapon)
	def getSecondaryWeapon(self):
		return(self.secondaryWeapon)
	def getDefense(self):
		return(self.defense)
	def getInventory(self):
		return(self.inventory)
	def getSpeed(self):
		return(self.speed)
	def getLuck(self):
		return(self.luck)
	def addToInventory(self, newWeapon):
		self.inventory.append(newWeapon)
		
	def isAttacking(self):
		return self.getaitype() == 'A'

	def validLandType(self,landType):
		return(self.motionType.validLandType(landType))
	
	def setPos(self,row,column):
		self.row=row
		self.column=column
		return
	def getStrength(self):
		return(self.strength)
	def __repr__(self):
		return(''.join(['utype=', self.utype,', motionType=',str(self.motionType),' movement=',str(self.movement),')',' inventory=',str(self.inventory),')']))
